package com.nari.ysphd.mip;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.util.Log;

import nari.mip.core.MipConstant;

/**
 * 令牌超时广播接收器
 */
public class MipTimeOutReceiver extends BroadcastReceiver {
    private static final String TAG = MipTimeOutReceiver.class.getSimpleName();

    private OnMipTimeOutListener onMipTimeOutListener;
    public MipTimeOutReceiver(OnMipTimeOutListener onMipTimeOutListener) {
        this.onMipTimeOutListener = onMipTimeOutListener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        Log.d(TAG, "onReceive: mip timeout");
        if (onMipTimeOutListener != null){
            onMipTimeOutListener.onMipTimeOut();
        }
    }

    public static void mipTimeOutRegisterReceiver(Context context, MipTimeOutReceiver receiver){
        context.registerReceiver(receiver, new IntentFilter(MipConstant.ACTION_SESSION_TIMEOUT));
    }

    public static void mipTimeOutUnregisterReceiver(Context context, MipTimeOutReceiver receiver){
        context.unregisterReceiver(receiver);
    }

    public interface OnMipTimeOutListener {
       void onMipTimeOut();
    }
}
